# -*- coding: utf-8 -*-
from flask import render_template, session, redirect, url_for
from . import admin
from ..funcs import get_permission



@admin.before_request 
def before_user(): 
    if 'user_id' in session:
        # 验证是否有权限
        per = get_permission(session['user_id'])
        if per != None:
            if int(per) >= 4:
                return
        else:
            return render_template('/admin/login.html')
    else:
        return redirect('/login')

@admin.route('/index')
def index():
    return render_template('admin/index.html')

# @admin.route('/login')
# def login():
#     return render_template('/admin/login.html')

@admin.route('/books')
def books():
    return render_template('admin/books.html')

@admin.route('/datas')
def datas():
    return render_template('admin/datas.html')

@admin.route('/setting')
def setting():
    return render_template('admin/setting.html')

@admin.route('/users')
def users():
    return render_template('admin/users.html')